<?php

namespace Chaosyeo\SolarEngine\Event;

class OrderProperties extends Properties
{
    protected $orderId;      // 订单 ID
    protected $payAmount;    // 订单金额
    protected $currencyType; // 货币类型
    protected $payType;      // 支付方式
    protected $status;       // 订单状态

    /**
     * @param float $payAmount 订单金额（必传）
     * @param string $currencyType 货币类型（必传）
     * @param array $params 可选参数数组，可包含：
     *   - orderId: string 订单 ID
     *   - payType: string 支付方式
     *   - status: string 订单状态
     */
    public function __construct(int $platform, float $payAmount, string $currencyType, array $params = [], array $customProperties = [])
    {
        if ($payAmount <= 0) {
            throw new \InvalidArgumentException('Pay amount must be greater than 0');
        }

        if (empty($currencyType)) {
            throw new \InvalidArgumentException('Currency type is required');
        }

        $this->payAmount    = $payAmount;
        $this->currencyType = $currencyType;

        // 验证并设置可选参数
        if (isset($params['orderId'])) {
            if (strlen($params['orderId']) > 128) {
                throw new \InvalidArgumentException('Order ID cannot exceed 128 characters');
            }
            $this->orderId = $params['orderId'];
        }

        if (isset($params['payType'])) {
            if (strlen($params['payType']) > 32) {
                throw new \InvalidArgumentException('Pay type cannot exceed 32 characters');
            }
            $this->payType = $params['payType'];
        }

        parent::__construct($platform, $params, $customProperties);
    }
}